Conversation
Replace the Polyfill NuGet package with a self-contained eng/Polyfills.cs file and project-specific polyfill extensions. - Remove Polyfill PackageReference from all 35 csproj files - Remove Polyfill configuration (PolyEnsure, PolyGuard, etc.) from Directory.Build.props - Remove PackageVersion from Directory.Packages.props - Remove global using Polyfills directives from csproj files - Add eng/Polyfills.cs with type stubs and attributes for older TFMs - Add project-specific polyfill extension methods where needed - Fix call sites for APIs not available on netstandard2.0/net462 Fixes #7596
There was a problem hiding this comment.
Pull request overview
This PR removes the third-party Polyfill NuGet dependency across the repo and replaces it with a shared, source-included polyfill implementation (eng/Polyfills.cs) plus a few project-scoped polyfill extension files to keep older TFMs building cleanly.
Changes:
- Removed
PolyfillPackageReferenceentries (and related MSBuild config/global usings) across projects. - Added
eng/Polyfills.csand wired it into builds viaDirectory.Build.props. - Updated call sites to avoid APIs/overloads not available on older TFMs (e.g.,
Enum.Parse<T>,Environment.ProcessId, async XML load/save, etc.).
Reviewed changes
Copilot reviewed 67 out of 67 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csproj | Removes Polyfill package reference. |
| test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csproj | Removes Polyfill package reference and Polyfills using. |
| test/Utilities/Automation.CLI/Automation.CLI.csproj | Removes Polyfill package reference. |
| test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj | Removes Polyfill package reference. |
| test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs | Switches to Split(char) overload for compatibility. |
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj | Removes Polyfill package reference and Polyfills using. |
| test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csproj | Removes Polyfill package reference. |
| test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj | Removes Polyfill package reference. |
| test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csproj | Removes Polyfill package reference. |
| test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.cs | Replaces Enum.GetValues<T>() with non-generic overload for older TFMs. |
| test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csproj | Removes Polyfill package reference. |
| test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.cs | Removes conditional using Polyfills;. |
| test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj | Removes Polyfill package reference. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj | Removes Polyfill package reference. |
| test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.cs | Removes using Polyfills;. |
| test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csproj | Removes Polyfill package reference. |
| test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csproj | Removes Polyfill package reference. |
| src/TestFramework/TestFramework/TestFramework.csproj | Removes Polyfill package reference and Polyfills using. |
| src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.cs | Replaces string.Join(char, …) with string separator overload for older TFMs. |
| src/TestFramework/TestFramework/Internal/PolyfillExtensions.cs | Adds TestFramework-scoped polyfill extensions. |
| src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.cs | Replaces string.Join(char, …) usage with string separator overload. |
| src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.cs | Adjusts flush logic to avoid FlushAsync(CancellationToken) dependency. |
| src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.cs | Replaces ConcurrentBag.Clear() with fallback loop for non-NETCOREAPP. |
| src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.cs | Replaces string.Join(char, …) usage with string separator overload. |
| src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj | Removes Polyfill package reference. |
| src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.cs | Adds polyfilled File.Move(overwrite) and async file-read fallback. |
| src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.cs | Adds Environment.ProcessId fallback for older TFMs. |
| src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.cs | Adds hashing/hex formatting fallbacks for older TFMs. |
| src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.cs | Adds Platform-scoped KeyValuePair Deconstruct polyfill. |
| src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs | Replaces Enum.Parse<T> with non-generic overload for older TFMs. |
| src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs | Replaces Enum.Parse<T> with non-generic overloads for older TFMs. |
| src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csproj | Removes Polyfill package reference. |
| src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.cs | Adds async XML save fallback for non-NETCOREAPP. |
| src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.cs | Adds async XML load fallback for non-NETCOREAPP. |
| src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.cs | Removes local EmbeddedAttribute in favor of shared polyfills file. |
| src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.cs | Adds Abstractions-scoped polyfill extensions (StringBuilder.AppendJoin). |
| src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.cs | Removes Polyfill-specific suppression entry. |
| src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csproj | Removes Polyfill package reference. |
| src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csproj | Removes Polyfill package reference. |
| src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csproj | Removes Polyfill package reference. |
| src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csproj | Removes Polyfill package reference. |
| src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj | Removes Polyfill package reference. |
| src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csproj | Removes Polyfill package reference. |
| src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csproj | Removes Polyfill package reference. |
| src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.cs | Removes local type polyfills in favor of shared eng/Polyfills.cs. |
| src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.cs | Adds analyzer-scoped polyfill extensions. |
| src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csproj | Removes Polyfill package reference. |
| src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csproj | Removes Polyfill package reference. |
| src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs | Replaces Environment.ProcessId usage with fallback. |
| src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.cs | Replaces string.Join(char, …) with string separator overload in updated call site. |
| src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs | Replaces Enum.Parse<T> with non-generic overload. |
| src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs | Adds adapter-scoped polyfill extensions (including CTS.CancelAsync for < net8). |
| src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.cs | Replaces generic Enum APIs with non-generic overloads for older TFMs. |
| src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.cs | Replaces Type.IsGenericMethodParameter usage with portable logic. |
| src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj | Removes Polyfill package reference and Polyfills using. |
| src/Adapter/MSTest.Engine/MSTest.Engine.csproj | Removes Polyfill package reference. |
| eng/Polyfills.cs | Adds shared repo-wide polyfill implementations and (conditionally) extension polyfills. |
| Directory.Packages.props | Removes Polyfill package version entry. |
| Directory.Build.props | Removes Polyfill MSBuild config and adds compilation of eng/Polyfills.cs. |
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.cs
Show resolved
Hide resolved
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.cs
Show resolved
Hide resolved
…d param - Add Polyfills.Guard, Polyfills.Ensure, and Polyfills.Polyfill backward- compatible types in eng/Polyfills.cs (guarded by IS_CORE_MTP) to prevent TypeLoadException/MissingMethodException when old extension packages reference these types from the platform assembly via InternalsVisibleTo. - Fix unused cancellationToken parameter in TrxReportEngine constructor for netstandard2.0 builds (addresses PR review comment).
| CS0436 is suppressed because InternalsVisibleTo causes the same internal polyfill types | ||
| to be visible from referenced assemblies; the local copy is intentionally preferred. --> | ||
| <PropertyGroup Condition="'$(Language)' != 'F#'"> | ||
| <NoWarn>$(NoWarn);CS0436</NoWarn> |
There was a problem hiding this comment.
We shouldn't suppress this.
Instead, we should ensure all polyfills have EmbeddedAttribute.
| { | ||
| internal static class IsExternalInit; | ||
|
|
||
| [global::System.AttributeUsage(global::System.AttributeTargets.Module | global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Method | global::System.AttributeTargets.Property | global::System.AttributeTargets.Event | global::System.AttributeTargets.Interface, Inherited = false)] |
There was a problem hiding this comment.
This should be class, struct, field, and property.
Looks like Field is missing, and Constructor/Method/Event are extra.
| internal sealed class RequiredMemberAttribute : Attribute { } | ||
|
|
||
| [global::System.AttributeUsage(global::System.AttributeTargets.All, AllowMultiple = true, Inherited = false)] | ||
| internal sealed class CompilerFeatureRequiredAttribute : Attribute |
There was a problem hiding this comment.
Let's match the original definition fully, and keep the constants defined in this class.
Replace the Polyfill NuGet package with a self-contained
eng/Polyfills.csfile and project-specific polyfill extension methods.Changes
PolyfillPackageReference from all 35 csproj filesPolyEnsure,PolyGuard,PolyStringInterpolation,PolyUseEmbeddedAttribute) fromDirectory.Build.propsPackageVersionentry fromDirectory.Packages.props<Using Include="Polyfills" />directives from 12 csproj filesusing Polyfills;from source filesGlobalSuppressionsentryReplacements
eng/Polyfills.cs— Shared polyfill types and attributes for older TFMs (netstandard2.0,net462): nullable attributes, compiler attributes,ExperimentalAttribute,Index/Range,Lock,OperatingSystem,UnreachableException,Ensurehelper, etc.src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.cssrc/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.cssrc/TestFramework/TestFramework/Internal/PolyfillExtensions.cssrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cssrc/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csCall-site fixes
Fixed code that relied on Polyfill-provided APIs not available on older TFMs:
SHA256.HashData,Convert.ToHexStringLower,Environment.ProcessId,File.Move(3-arg),File.ReadAllTextAsync,Enum.Parse<T>,Enum.GetNames<T>,Enum.IsDefined<T>,Enum.GetValues<T>,XElement.LoadAsync,XDocument.SaveAsync,Type.IsGenericMethodParameter,string.Join(char, ...),ConcurrentBag.Clear,ConcurrentDictionary.GetOrAdd(3-arg), andTextWriter.FlushAsync(CancellationToken).Fixes #7596